<template>
	<view class="technician">
		<technicianDom :tab_type='true' :list='tece' :obj='from' :dz='dz' :dzlist='dz_list'></technicianDom>
	</view>
</template>

<script>
	import bus from '../../config/emit.js'
	import technicianDom from '../../components/technician_dom/technician_dom.vue'
	import{ addressAnalysis } from '../../config/index.js'
	export default {
		components: {
			technicianDom
		},
		data() {
			return {
				falg: true,
				from: {
					cid: 0,
					search: '',
					goods_id: '',
					lng: '',
					lat: '',
					order_field: 'distance',
					page: '1',
					city: ''
				},
				tece: [],
				dz: '',
				dz_list: []
			};
		},
		onLoad(option) {
			this.wz()
			bus.$on('refresh', res => {
				this.from.page=1
				this.falg = true
				this.tece = []
				this.getTechList()
			});
		},
		methods: {
			getTechList() {
				this.$httpRequest('/tech/getTechList', this.from).then(res => {
					if (res.data.last_page > res.data.current_page) {
						this.from.page++;
					} else {
						this.falg = false
					}
					this.tece.push(...res.data.data)
				})
			},
			wz() {
				let that = this
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: function(res) {
						// that.dz = res.address.city
						that.from.lng = res.longitude
						that.from.lat = res.latitude
						if(!res.longitude || !res.latitude){
							uni.showToast({
								icon:"fail",
								title:"获取定位失败",
								duration:2000,
							});
							return;
						}
						that.$httpRequest('/tech/locationAnalysis',{lng:res.longitude,lat:res.latitude}).then(res=>{
							that.dz = res.data.address_component.city;
							that.from.city=res.data.ad_info.adcode
							that.getTechList()
						});
					}
				});
			},
		},
		// 触底刷新
		onReachBottom() {
			if (this.falg) {
				this.getTechList();
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.from.page=1
			this.falg = true
			this.tece = []
			this.getTechList();
			uni.stopPullDownRefresh();
		},
	}
</script>

<style lang="less">
	.technician {
		padding-bottom: 75rpx;
		box-sizing: border-box;
	}
</style>